from PySide6.QtCore import QSize, QDate, Qt
from PySide6.QtGui import QFont, QIcon
from PySide6.QtWidgets import QWidget, QHBoxLayout, QLabel, QSizePolicy, QToolButton, QSpacerItem
from qfluentwidgets import ZhDatePicker, FluentIcon, ToolButton
from DAO import UserDAO


class TopBar(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setFixedHeight(50)
        self.setupUi()

    def setupUi(self):
        self.layout = QHBoxLayout(self)
        self.layout.setSpacing(7)
        self.layout.setContentsMargins(15, 5, 15, 5)

        self.usernameLabel = QLabel("Hi, username", self)
        if UserDAO.currentUser:
            self.usernameLabel.setText("Hi, " + UserDAO.currentUser.username)
        self.usernameLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.usernameLabel.setMinimumSize(QSize(100, 40))
        self.usernameLabel.setMaximumSize(QSize(269, 16777215))
        font = QFont()
        font.setPointSize(12)
        self.usernameLabel.setFont(font)
        self.layout.addWidget(self.usernameLabel, alignment=Qt.AlignLeft | Qt.AlignVCenter)

        self.helpBtn = ToolButton(self)
        self.helpBtn.setMinimumSize(QSize(35, 35))
        icon = FluentIcon.HELP
        self.helpBtn.setIcon(icon)
        self.layout.addWidget(self.helpBtn, alignment=Qt.AlignLeft | Qt.AlignVCenter)

        self.layout.addSpacerItem(QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))

        self.dateStrip = ZhDatePicker(self)
        self.dateStrip.setDate(QDate.currentDate())
        self.dateStrip.setMinimumSize(QSize(150, 35))
        self.dateStrip.setFont(font)
        self.layout.addWidget(self.dateStrip, alignment=Qt.AlignRight | Qt.AlignVCenter)

        self.visit_nmusLabel = QLabel("次/访问", self)
        self.visit_nmusLabel.setMinimumSize(QSize(80, 35))
        font1 = QFont()
        font1.setPointSize(10)
        self.visit_nmusLabel.setFont(font1)
        self.visit_nmusLabel.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
        self.layout.addWidget(self.visit_nmusLabel, alignment=Qt.AlignRight | Qt.AlignVCenter)
